﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAI.nQueens;
using SAI.RouteFinding;
using System.IO;

namespace SAI
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arena2_scenarios = new int[]{11,21,62,127,185,254,316,371,439,501,566,622,688,749};
            int[] brc000d_scenarios = new int[] {11,30,65,125,190,257,317,379,431,507,569,628,686,750};
            //int[] brc100d_scenarios = new int[] {20,28,70,122,183,248,318,373,433,509,568,625,689,760};
            int[] brc100d_scenarios = new int[15];
            for (int i = 31; i <= 45; i++)
                brc100d_scenarios[i-31] = i;
            Console.WriteLine("brc100d.map");
            Console.WriteLine("--------------------------------------BFS--------------------------------------");
            for (int i = 0; i < brc100d_scenarios.Length; i++)
            {
                Console.WriteLine("Started Scenario " + brc100d_scenarios[i]);
                Maze maze = new Maze("brc100d.map", brc100d_scenarios[i]);
                Node BFSMazeRes = BFS.search(maze.Start, maze.Goal);
                maze.printSolution();
                StreamWriter solutionWriter = new StreamWriter("BFSbrc100d_map " + brc100d_scenarios[i].ToString() + ".txt");
                solutionWriter.Write(BFS.metrics.NodesExpanded.ToString() + '\n' + BFS.metrics.NodesGenerated + '\n' + maze.SolutionLength + '\n' + BFS.metrics.DupNodes.Count);
                solutionWriter.Close();
            }
            Console.WriteLine("--------------------------------------ID--------------------------------------");
            for (int i = 0; i < brc100d_scenarios.Length; i++)
            {
                Console.Write("Started Scenario " + brc100d_scenarios[i] + ": ");
                Maze maze = new Maze("brc100d.map", brc100d_scenarios[i]);
                Node IDMazeRes = ID.IDDFS(maze.Start, maze.Goal);
                maze.printSolution();
                StreamWriter solutionWriter = new StreamWriter("IDbrc100d_map " + brc100d_scenarios[i].ToString() + ".txt");
                solutionWriter.Write(ID.metrics.NodesExpanded.ToString() + '\n' + ID.metrics.NodesGenerated + '\n' + maze.SolutionLength + '\n' + ID.metrics.DupNodes.Count);
                solutionWriter.Close();
                Console.WriteLine();
            }


            List<KeyValuePair<double, double>> sizes = new List<KeyValuePair<double, double>>();
            List<KeyValuePair<int, int>> nodes = new List<KeyValuePair<int, int>>();
            List<KeyValuePair<int, int>> dup = new List<KeyValuePair<int, int>>();
            for (int i = 4; i <= 13; i++)
            {
                NQueensProblem p = new NQueensProblem(i);
                Node BFSQueen = BFS.search(p.Start, p.Goal);
                Node IDQueen = ID.IDDFS(p.Start, p.Goal);
                nodes.Add(new KeyValuePair<int, int>(BFS.metrics.NodesExpanded, ID.metrics.NodesExpanded));
                dup.Add(new KeyValuePair<int, int>(BFS.metrics.DupNodes.Count, ID.metrics.DupNodes.Count));
                sizes.Add(new KeyValuePair<double, double>(BFS.metrics.Size, ID.metrics.Size));           
            }
            StreamWriter sizesFile = new StreamWriter("Size.csv");
            foreach (KeyValuePair<double,double> size in sizes)
            {
                sizesFile.WriteLine(size.Key + "," + size.Value);
            }
            sizesFile.Close();
            StreamWriter nodeFile = new StreamWriter("Nodes.csv");
            foreach (KeyValuePair<int, int> size in nodes)
            {
                nodeFile.WriteLine(size.Key + "," + size.Value);
            }
            nodeFile.Close();
            StreamWriter dupFile = new StreamWriter("Dup.csv");
            foreach (KeyValuePair<int, int> size in dup)
            {
                dupFile.WriteLine(size.Key + "," + size.Value);
            }
            dupFile.Close();
            
         }
    }
}
